<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <script>
        var request = window.indexedDB.open("myBooks", 1);
        request.onerror = function(event) {
            alert("数据库连接失败：" + event.target.errorCode);
        }
        request.onupgradeneeded = function(event) {
            //当此数据库创建前不存在时，进行初始化
            var db = request.result;
            var store = db.createObjectStore("books", {
                keyPath: "isbn"
            });
            var titleIndex = store.createIndex("by_title", "title", { //标题索引
                unique: true
            });
            var authorIndex = store.createIndex("by_author", "author"); //作者索引
            //填入初始值，添加2本书信息
            store.put({
                title: "计算机组成原理（修订版）",
                author: "张功萱",
                isbn: 9787302433637
            });
            store.put({
                title: "Java 2实用教程（第5版）",
                author: "耿祥义",
                isbn: 9787302464259
            });
        }
        request.onsuccess = function(event) { //捕获连接成功事件，并处理
            db = event.target.result; //连接成功时，获取数据库对象（也可用request.result）
            alert("数据库连接成功");
        }
    </script>
</head>

<body>
</body>

</html>